package com.joysuch.wwyt.util;

import java.math.BigDecimal;

/**
 * @Author ZhangDong
 * @Date 2020/5/6 11:33
 */
public class FloatUtil {


    /**
     * 小数位数小于两位
     */
    public static boolean judgeFloat(float f) {
        String string = String.valueOf(f);
        //f较大时 保留俩位小数
        if (f > 1000000) {
            BigDecimal d1 = new BigDecimal(Double.toString(f));
            BigDecimal d2 = new BigDecimal(Integer.toString(1));
            string = d1.divide(d2, 2, BigDecimal.ROUND_HALF_UP).toString();
        }
        int i = string.indexOf(".");
        if (i == -1) {
            return true;
        }
        if (string.substring(i + 1).length() > 2) {
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(judgeFloat(2.432f));
    }
}
